/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author dchapman
 */
@Entity
@Table(name = "posLoyaltyCard")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PosLoyaltyCard.findAll", query = "SELECT p FROM PosLoyaltyCard p ORDER BY p.lastName ASC"),
    @NamedQuery(name = "PosLoyaltyCard.findByPhoneNumber", query = "SELECT p FROM PosLoyaltyCard p WHERE p.phoneNumber = ?1"),
    @NamedQuery(name = "PosLoyaltyCard.findByCardNumber", query = "SELECT p FROM PosLoyaltyCard p WHERE p.cardNumber = ?1"),
    @NamedQuery(name = "PosLoyaltyCard.findByLastFirstName", query = "SELECT p FROM PosLoyaltyCard p WHERE p.lastName = ?1 AND p.firstName = ?2"),
    @NamedQuery(name = "PosLoyaltyCard.findByGrowlerCount", query = "SELECT p FROM PosLoyaltyCard p WHERE p.growlerCount = :growlerCount")})
public class PosLoyaltyCard implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "loyaltyID")
    private Integer loyaltyID;
    @Column(name = "phoneNumber")
    private BigInteger phoneNumber;
    @Column(name = "cardNumber")
    private BigInteger cardNumber;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 50)
    @Column(name = "lastName")
    private String lastName;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 50)
    @Column(name = "firstName")
    private String firstName;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 250)
    @Column(name = "email")
    private String email;
    @Basic(optional = false)
    @NotNull
    @Column(name = "birthday")
    @Temporal(TemporalType.DATE)
    private Date birthday;
    @Basic(optional = false)
    @NotNull
    @Column(name = "earnedPoints")
    private int earnedPoints;
    @Basic(optional = false)
    @NotNull
    @Column(name = "currentBalance")
    private float currentBalance;
    @Basic(optional = false)
    @NotNull
    @Column(name = "growlerCount")
    private int growlerCount;
    @Basic(optional = false)
    @NotNull
    @Column(name = "earnedGrowlers")
    private int earnedGrowlers;
    @OneToMany(mappedBy = "loyaltyCard")
    private Collection<POSSale> posSaleCollection;

    public PosLoyaltyCard() {
    }

    public PosLoyaltyCard(Integer loyaltyID) {
        this.loyaltyID = loyaltyID;
    }

    public PosLoyaltyCard(Integer loyaltyID, String lastName, String firstName, String email, Date birthday, int earnedPoints, float currentBalance, int growlerCount) {
        this.loyaltyID = loyaltyID;
        this.lastName = lastName;
        this.firstName = firstName;
        this.email = email;
        this.birthday = birthday;
        this.earnedPoints = earnedPoints;
        this.currentBalance = currentBalance;
        this.growlerCount = growlerCount;
    }

    public Integer getLoyaltyID() {
        return loyaltyID;
    }

    public void setLoyaltyID(Integer loyaltyID) {
        this.loyaltyID = loyaltyID;
    }

    public BigInteger getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(BigInteger phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public BigInteger getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(BigInteger cardNumber) { 
        if(cardNumber != null){
            this.cardNumber = cardNumber;
        }
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public int getEarnedPoints() {
        return earnedPoints;
    }

    public void setEarnedPoints(int earnedPoints) {
        this.earnedPoints = earnedPoints;
    }

    public float getCurrentBalance() {
        return currentBalance;
    }

    public void setCurrentBalance(float currentBalance) {
        this.currentBalance = currentBalance;
    }

    public int getGrowlerCount() {
        return growlerCount;
    }

    public void setGrowlerCount(int growlerCount) {
        this.growlerCount = growlerCount;
    }

    public int getEarnedGrowlers() {
        return earnedGrowlers;
    }

    public void setEarnedGrowlers(int earnedGrowlers) {
        this.earnedGrowlers = earnedGrowlers;
    }

    @XmlTransient
    public Collection<POSSale> getPosSaleCollection() {
        return posSaleCollection;
    }

    public void setPosSaleCollection(Collection<POSSale> posSaleCollection) {
        this.posSaleCollection = posSaleCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (loyaltyID != null ? loyaltyID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PosLoyaltyCard)) {
            return false;
        }
        PosLoyaltyCard other = (PosLoyaltyCard) object;
        if ((this.loyaltyID == null && other.loyaltyID != null) || (this.loyaltyID != null && !this.loyaltyID.equals(other.loyaltyID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.PosLoyaltyCard[ loyaltyID=" + loyaltyID + " ]";
    }
    
}
